/**
 * author:wos
 * time:2024-1-4
 * title:删除用户
 */

const parseQueryParams = require("../../../utils/parseQueryParams");

async function del(ctx, next) {
    const tableName = "sys_user"
    const tableIndexName = 'userId'

    const url = ctx.request.url
    const query = Object.assign({}, parseQueryParams(url))

    if (query[tableIndexName] === undefined) {
        global.response(ctx, {
            "status": 200,
            "code": 500,
            "data": {},
            "msg": '参数错误'
        })
    } else {
        try {
            const sql =
                `delete from ${tableName} where ${tableIndexName} = ${query[tableIndexName]} and type != '1';
                delete from sys_user_role where userId = ${query[tableIndexName]}; delete from sys_user_post where userId = ${query[tableIndexName]};`
            console.log(sql);
            let rs = await global.query(sql)
            global.response(ctx, {
                "status": 200,
                "code": 200,
                "data": rs,
                "msg": 'success'
            })
        } catch (err) {
            global.serverError(ctx)
        }
    }
}

module.exports = del